package com.example.waibao.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result extends HashMap<String, Object> {

    private boolean success;
//    private String username;
    private Object data;
    private String msg;
    private int code;

    public static Result success(Object data){
        return new Result(true, data, "success", 200);
    }

    public static Result ok(String msg){
        Result r = new Result();
        r.put("msg", msg);
        return  r;
    }

    public static Result error(int code, String msg){
        Result r = new Result();
        r.put("code", code);
        r.put("msg", msg);
        return  r;
    }
    public static Result ok(Map<String, Object> map){
        Result r = new Result();
        r.putAll(map);
        return  r;
    }
    public static Result ok(){return new Result();}

    public Result put(String key, Object value) {
        super.put(key, value);
        return this;
    }

    public static Result fail(int code,String msg){
        return new Result(false, null, msg, code);
    }

}
